' assemblerplugin.bmx

Strict

Import BRL.Basic

Import "../maxtk/maxtk.bmx"
Import "textplugin.bmx"

Type TAssemblerOptions Extends TTextOptions	
	Method CreateAssemblerOptions:TAssemblerOptions(plugin:TAssemblerPlugin)
		CreateTextOptions(plugin)
		SetName "Assembler Options"
		Return Self
	End Method
End Type

Type TAssemblerPlugin Extends TTextPlugin

	Method Open:Object(path$)
		Return TAssemblerCode.OpenAssemblerCode(Self,path)
	End Method
	
	Method Initialize(owner:THost)
		host=owner
		SetName("Assembler Files",["s","asm"])
		editor=TEditor(host)
		If Not editor RuntimeError "AssemblerPlugin requires TEditor Host"
		options=New TAssemblerOptions.CreateAssemblerOptions(Self)
		editmenu=CreateEditMenu()
	End Method

End Type

Type TAssemblerCode Extends TTextCode
	Field	plugin:TAssemblerPlugin
	Field	options:TAssemblerOptions

	Function OpenAssemblerCode:TAssemblerCode(plugin:TAssemblerPlugin,path$)
		Local	code:TAssemblerCode

		code=New TAssemblerCode

		code.plugin=plugin
		code.host=plugin.host
		code.options=TAssemblerOptions(plugin.options)
		
		code.active=True
		code.path=path
		code.host.addpanel(code)		
		
		code.textarea=CreateTextArea(0,0,ClientWidth(code.panel),ClientHeight(code.panel),code.panel,0)
		SetTextAreaText code.textarea,"~n"
		SetGadgetLayout code.textarea,1,1,1,1
		code.Refresh
		code.SetDirty False		
		plugin.host.UpdateProgress "Reading Stream"
		code.ReadSource(path)
		code.UpdateCode
		code.undolist.clear
' cludge first dirty		
		code.filesrc=TextAreaText(code.textarea)
		code.SetDirty False
		Return code
	End Function

	Method OnEvent()
 		Select EventSource()
			Case textarea 
				Select EventID() 
					Case EVENT_KEYCHAR
						If EventData()=13 And plugin.options.autoindent AutoIndent 
						Return
					Case EVENT_MOUSEUP
						If EventData()=2
							PopupWindowMenu host.window,plugin.editmenu
						EndIf
					Case EVENT_GADGETACTION
						UpdateCode
					Case EVENT_GADGETSELECT
						UpdateCursor
				End Select
		End Select
	End Method

	Method SetCode(src$,diff:TDiff=Null)
		Local	i,p,p1,q,r,a,t$,h$,lsrc$,r0,r1,cpos,autocap
		Local	s:TTextStyle
' update dirty flag	
		CheckDirty src
		If src=cleansrc And Not deferpos And Not diff Return	
		cleansrc=src
		cleansrcl=src.ToLower()
	End Method

	Method Refresh()
		Local	rgb:TColorButton
		Local	src$
		SetTextAreaTabs textarea,options.tabsize.value
		SetTextAreaFont textarea,options.editfont.font
		rgb=options.editcolor
		SetTextAreaColor textarea,rgb.red,rgb.green,rgb.blue,True
		rgb=options.editstyle.color
		SetTextAreaColor textarea,rgb.red,rgb.green,rgb.blue,False
		src=cleansrc
		cleansrc=""
		cleansrcl=""
		cursorpos=0
		SetCode(src)
	End Method
End Type


